package org.hilo.boot.core.dubbo;

import com.alibaba.dubbo.rpc.RpcException;

/**
 * 
 * @author zollty
 * @since 2020年11月10日
 */
public enum DubboStatus {
    UNKNOWN(0),
    NETWORK(1),
    TIMEOUT(2),
    BIZ(3),
    FORBIDDEN(4),
    SERIALIZATION(5);
    
    public static final String DUBBO_ERROR = "DUBBO_ERROR";
    public static final String BIZ_ERROR = "BIZ_ERROR";
    
    private int status;
    
    private DubboStatus(int status) {
        this.status = status;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     */
    public static DubboStatus getByCode(int code) {
        for (DubboStatus _enum : values()) {
            if (_enum.getStatus() == code) {
                return _enum;
            }
        }
        return null;
    }
    
    /**
     * 通过枚举<code>code</code>获得枚举
     */
    public static DubboStatus getByException(RpcException ex) {
        return getByCode(ex.getCode());
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

}
